{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "82b04196",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入支付宝余额：3000\n",
      "----------- goods -----------\n",
      "商品 0 ,名称：香水 ,价格：500 元\n",
      "商品 1 ,名称：荔枝 ,价格：200 元\n",
      "商品 2 ,名称：饺子 ,价格：100 元\n",
      "商品 3 ,名称：西瓜 ,价格：50 元\n",
      "请输入要购买的商品编号：0\n",
      "您的商品：【香水】购买成功，您的余额还有：2500\n",
      "----------- goods -----------\n",
      "商品 0 ,名称：香水 ,价格：500 元\n",
      "商品 1 ,名称：荔枝 ,价格：200 元\n",
      "商品 2 ,名称：饺子 ,价格：100 元\n",
      "商品 3 ,名称：西瓜 ,价格：50 元\n",
      "请输入要购买的商品编号：1\n",
      "您的商品：【荔枝】购买成功，您的余额还有：2300\n",
      "----------- goods -----------\n",
      "商品 0 ,名称：香水 ,价格：500 元\n",
      "商品 1 ,名称：荔枝 ,价格：200 元\n",
      "商品 2 ,名称：饺子 ,价格：100 元\n",
      "商品 3 ,名称：西瓜 ,价格：50 元\n",
      "请输入要购买的商品编号：2\n",
      "您的商品：【饺子】购买成功，您的余额还有：2200\n",
      "----------- goods -----------\n",
      "商品 0 ,名称：香水 ,价格：500 元\n",
      "商品 1 ,名称：荔枝 ,价格：200 元\n",
      "商品 2 ,名称：饺子 ,价格：100 元\n",
      "商品 3 ,名称：西瓜 ,价格：50 元\n",
      "请输入要购买的商品编号：3\n",
      "您的商品：【西瓜】购买成功，您的余额还有：2150\n",
      "----------- goods -----------\n",
      "商品 0 ,名称：香水 ,价格：500 元\n",
      "商品 1 ,名称：荔枝 ,价格：200 元\n",
      "商品 2 ,名称：饺子 ,价格：100 元\n",
      "商品 3 ,名称：西瓜 ,价格：50 元\n"
     ]
    }
   ],
   "source": [
    "# 商品信息\n",
    "list = [\n",
    "    [\"香水\", 500],\n",
    "    [\"荔枝\", 200],\n",
    "    [\"饺子\", 100],\n",
    "    [\"西瓜\", 50]\n",
    "       ]\n",
    "shopping_car = []\n",
    "money = int(input(\"请输入支付宝余额：\"))\n",
    "\n",
    "while True:\n",
    "    print(\"----------- goods -----------\")\n",
    "    \n",
    "    for i in range(len(list)):\n",
    "        print(\"商品 %s ,名称：%s ,价格：%s 元\"%(i,list[i][0],list[i][1]))\n",
    "    \n",
    "    choice = input(\"请输入要购买的商品编号：\")\n",
    "    if choice.isdigit():   # isdigit 判断字符串里的内容是否为数值\n",
    "        choice = int(choice)\n",
    "        if choice < len(list):\n",
    "            ## 1.编号存在，判断余额\n",
    "                ### 余额够，余额 - 价格\n",
    "            if money > list[i][1]:\n",
    "                shopping_car.append(list[choice])\n",
    "                money = money - list[choice][1]\n",
    "                print(\"您的商品：【%s】购买成功，您的余额还有：%s\"%(list[choice][0],money))\n",
    "                ### 余额不足，购买失败\n",
    "            else:\n",
    "                print(\"您的余额不足，请充值～\")\n",
    "                \n",
    "                \n",
    "            ## 2.编号不存在，重新输入\n",
    "        else:\n",
    "            print(\"您输入的编号不存在，请重新输入\")\n",
    "    elif choice == \"退出\":\n",
    "        print(\"您的购物车：\",shopping_car/n)\n",
    "        print(\"您的余额是：\",money)\n",
    "        break\n",
    "    else:\n",
    "        print(\"请输入编号！！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "98672805",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
